﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System;
using System.IO;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using Sci7z.Properties;


namespace Sci7z
{
    public class Depends
    {
        private static string ComBineArgs(string[] args)
        {
            string str = "";
            foreach (string str2 in args)
            {
                string str3 = str2.Trim().Trim(new char[] { '"' });
                str = str + " \"" + str3 + "\"";
            }
            return str.Substring(1);
        }

        public static string curDir()
        {
            return AppDomain.CurrentDomain.BaseDirectory;
        }

        public static string curExecutablePath()
        {
            return Application.ExecutablePath;
        }

        /// <summary>
        /// 导出内部资源文件
        /// </summary>
        public static void Export()
        {
            string path = curDir() + "7z.dll";
            string path2 = curDir() + "7z.exe";
            if (!File.Exists(path) || !File.Exists(path2))
            {
                if (!File.Exists(path))
                {
                    SaveFile(Resources._7z, path, false);
                }
                if (!File.Exists(path2))
                {
                    SaveFile(Resources._7z1, path2, false);
                }
            }
        }

        public static void SaveFile(byte[] array, string path, bool repalce = false)
        {
            if (repalce && File.Exists(path))
            {
                File.Delete(path);
            }
            if (!File.Exists(path))
            {
                string directoryName = Path.GetDirectoryName(path);
                FileStream stream = new FileStream(path, FileMode.Create);
                stream.Write(array, 0, array.Length);
                stream.Close();
            }
        }
    }
}
